package showtime.framework.manager
{
	import flash.text.TextFormat;
	import flash.utils.Dictionary;
	
	import showtime.framework.core.pattern.Singleton;
	import showtime.framework.manager.supportClasses.style.Style;
	
	/** 
	 * @project showtime
	 * @author yinhao
	 * @date 2011-2-19
	 *
	 */
	
	public class StyleManager extends Singleton
	{
		private var cache:Dictionary = null;
		/**
		 * Singleton pattern. 
		 * @return 
		 * 
		 */		
		static public function getInstance():StyleManager
		{
			return StyleManager(Singleton.getInstanceOrCreate(StyleManager));
			
		}
		
		/**
		 * Settings. 
		 * 
		 */
		override protected function initialize():void
		{		
			cache = new Dictionary();
		}
		
		public function registerStyle(style:Style):void
		{
			cache[style.id] = style;
		}
		
		public function getStyle(id:String):Style
		{
			if (cache.hasOwnProperty(id))
			{
				return cache[id];	
			}
			
			return null;			
		}
		
		public function getStyleAsTextFormat(id:String):TextFormat
		{
			var style:Style = getStyle(id);
			
			if (style != null)
			{
				var format:TextFormat = new TextFormat();
				format.bold = style.bold;
				format.size = style.size;
				format.color = style.color;
				format.font = style.font;
				
				return format;
			}
			
			return null;
		}
	}
}